﻿
using Abp.Application.Services.Dto;
using Abp.Web.Models;
using Abp.Web.Mvc.Authorization;
using KDS.Mes.Authorization;
using KDS.Mes.Mes.SeatPositions;
using KDS.Mes.Mes.SeatPositions.Dtos;
using KDS.Mes.Web.Models.SeatPositions;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace KDS.Mes.Web.Controllers
{
    public class SeatPositionsController : MesControllerBase
    {

        private readonly ISeatPositionAppService _seatPositionAppService;

        public SeatPositionsController(ISeatPositionAppService seatPositionAppService)
        {
            _seatPositionAppService = seatPositionAppService;

        }

        public ActionResult Index()
        {
            //var model = new GetSeatPositionInput { FilterText = Request.QueryString["filterText"] };
            return View();
        }
        [DontWrapResult]
        public JsonResult GetAllSeatPositions(int limit, int offset, string sortfiled, string sortway)
        {
            var sort = !string.IsNullOrEmpty(sortfiled) ? string.Format("{0} {1}", sortfiled, sortway) : "";
            var filter = new GetSeatPositionInput
            {
                SkipCount = offset,
                MaxResultCount = limit,
                Sorting = sort,
            };
            var pagedTasks = _seatPositionAppService.GetPagedSeatPositions(filter);
            return Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_Bom_SeatPositions_Create, AppPermissions.Pages_Bom_SeatPositions_Edit)]
        public async Task<PartialViewResult> CreateOrEditSeatPositionModal(int? id)
        {
            var input = new NullableIdDto<int> { Id = id };

            var output = await _seatPositionAppService.GetSeatPositionForEditAsync(input);

            var viewModel = new CreateOrEditSeatPositionModalViewModel(output);


            return PartialView("_CreateOrEditSeatPositionModal", viewModel);
        }


    }
}